import { debounce } from '@/utils'

export default {
  beforeMount(el, { value, arg = 'click' }, vnode) {
    const bindEvent = value
    const event = arg
    const time = 500
    const debounced = debounce(bindEvent, time, vnode)

    el.addEventListener(event, debounced)
    el._debounced = debounced
    el._event = event
  },
  beforeUnmount(el) {
    el.removeEventListener(el._event, el._debounced)
  },
}
